<template>
    <div class="userSet">
        <header>账号设置</header>
        <div class="contents">
            <div class="ad_list">
                <div class="condition_1">
                    <div class="market_type">
                        <span>账号状态：</span>
                        <el-select clearable v-model="userStatus" placeholder="请选择" style="width:300px;">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </div>
                    <div class="status">
                        <span>关键词：</span>
                        <el-input v-model.trim="keyword" placeholder="编号/姓名/联系方式" style="width:300px;"></el-input>
                    </div>
                    <el-button type="danger" style="background:#e7251a;" @click.native="querys">查询</el-button>
                    <el-button @click.native="resets">重置</el-button>
                </div>
                <div class="ad_list_title">
                    <el-button type="danger" style="background:#e7251a;" @click.native="userAdd">新增账号</el-button>
                </div>
            </div>
            <div class="selected" v-if="selectArr.length>0">
                <p>
                    <img src="../../assets/images/market/select2.png" alt="" />
                    <span>已选择&nbsp;
                        <label>{{selectArr.length}}</label>&nbsp;项</span>
                </p>
            </div>
            <div class="tables">
                <el-table v-loading="loading" :data="actList" style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column type="index" label="排序" width="50"> </el-table-column>
                    <el-table-column prop="compName" label="所属门店" width="200"> </el-table-column>
                    <el-table-column prop="compId" label="编号" width="200"> </el-table-column>
                    <el-table-column prop="userName" label="姓名" width="200"> </el-table-column>
                    <el-table-column prop="loginPwd" label="密码" width="200"> </el-table-column>
                    <el-table-column prop="mobilePhone" label="联系方式" width="200"> </el-table-column>
                    <el-table-column prop="status" label="状态" width="200">
                        <template slot-scope="scope">
                            <span v-if="scope.row.status==1" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_green.png" width="16" heigth="16" alt="" />启用 </span>
                            <span v-if="scope.row.status==0" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_red.png" width="16" heigth="16" alt="" />停用 </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="options" label="操作" width="150">
                        <template slot-scope="scope">
                            <span v-if="scope.row.status==1" class="opretions" @click="changes(scope.row.id,scope.row.status)">停用</span>
                            <span v-else class="opretions" @click="changes(scope.row.id,scope.row.status)">启用</span>
                            <span class="opretions" @click="goEdit(scope.row.id)">编辑</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[6, 8, 10]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="tableDatas.COUNT"> </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        name: "userSet",
        data() {
            return {
                userStatus: "",//账号状态
                keyword: "", //关键字
                // 筛选当前会员状态选项
                options: [
                {
                    value: 1,
                    label: "启用"
                },
                {
                    value: 0,
                    label: "停用"
                }],
                // 用户列表数据
                tableDatas: [],
                currentPage4: 1,
                selectArr: [], //已选择的数组集合
                loading:true,
                page:1,
                pageSize:6,
            };
        },
        computed:{
        	//请求参数
        	objs(){
        		let obj = {};
        		obj.PAGE_NO = this.page;
        		obj.PAGE_SIZE = this.pageSize;
        		if(this.userStatus === 0 || this.userStatus){
        			obj.STATUS = this.userStatus;	
        		}        		
        		this.keyword ? obj.LIKESTR = this.keyword : null;
        		return obj;
        	},
        	//分页数据
        	actList(){
        		if(this.tableDatas.CAFEUSERARR){
        			return this.tableDatas.CAFEUSERARR;
        		}
        	},
        },
        created() {
        	this.getList();
        },
        methods: {
        	//账号列表
        	getList(){
        		this.loading = true;
        		this.$axiosPost('/4SCAFE/cafeUser/getCafeUserList.action',this.objs).then(res => {        			
        			if(res.STATUS_CODE === 1){
        				this.loading = false;
        				this.tableDatas = res;
        			}
        		})
        	},
            handleSelectionChange(val) {
                this.selectArr = val;
                //console.log(this.selectArr);
            },
            handleSizeChange(val) {
            	this.loading = true;
                this.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.loading = true;
                this.page = val;
                this.getList();
            },
            //搜索
            querys() {                
                this.getList();
            },
            //重置
            resets(){
            	this.userStatus = this.keyword = '';
            },
            //停用、启用
            changes(id,status){
            	this.$axiosPost('/4SCAFE/cafeUser/cafeUserUptoDown.action',{
            		CAFEUSER_ID:id,
            		STATUS: status === 1 ? 0 : 1
            	}).then(res => {
            		if(res.STATUS_CODE === 1){
            			this.$message.success('状态已改变');
            			this.getList();
            		}
            	})
            },
            //新增门店
            userAdd() {
                this.$router.push({
                    path: "/setting/userAdd"
                });
            },
            //编辑
            goEdit(id){            	
            	this.$router.push({
            		path:'/setting/userEdit/'+id
            	})
            },
        },        
    };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .userSet {
        header {
            background: #fff;
            font-size: 22px;
            font-weight: 700;
            padding: 20px;
        }
        .contents {
            width: 97%;
            margin: 25px auto;
            padding: 15px 25px;
            background: #fff;
            .ad_list {
                align-items: center;
                justify-content: space-between;
                .condition_1 {
                    -webkit-display: flex;
                    display: flex;
                    .status {
                        margin: 0 35px;
                    }
                }
                .ad_list_title {
                    height: 68px;
                    margin-top: 40px;
                    font-size: 20px;
                }
                .ad_list_tab {
                    display: flex;
                    padding-top: 10px;
                }
            }
            .selected {
                margin-top: 15px;
                border: 1px solid #f0f0f0;
                border-radius: 5px;
                background: #fafafa;
                p {
                    display: flex;
                    align-items: center;
                    img {
                        width: 20px;
                        height: 20px;
                        margin: 0 10px;
                    }
                    span {
                        font-size: 16px;
                        color: #717a7d;
                        label {
                            color: #e7251a;
                        }
                    }
                }
            }
            .tables {
                .el-pagination {
                    text-align: center;
                    margin-top: 30px;
                }
                .opretions {
                    color: #1d93ff;
                    cursor: pointer;
                    margin: 0 2px;
                    &:hover {
                        text-decoration: underline;
                    }
                }
            }
        }
    }
</style>